using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Xml;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Data.Database;

namespace AMFC.Manager.Underwriting {
	public class Properties : System.Web.UI.Page {
		protected Literal ltrProps;
		protected Literal ltrHMDAProps;
		protected Literal ltrCategories;
		protected Literal ltrPropertyTypeTypeID;

		private void Page_Load(object sender, System.EventArgs e) {
			UOX uox = new UOX();
			ltrProps.Text = SQLX.ADOToString(uox.dbADO,"SELECT * FROM ts_PropertyType ORDER BY Name");
			ltrHMDAProps.Text = BuildSelectOptions(SQLX.ExecuteDatasetEx(uox.db,"SELECT * FROM ts_HMDA_PropertyType").Tables[0],"Name","ID");
			ltrCategories.Text = BuildSelectOptions(SQLX.ExecuteDatasetEx(uox.db,"SELECT * FROM ts_PropertyCategory").Tables[0],"Name","ID");
			ltrPropertyTypeTypeID.Text = BuildSelectOptions(SQLX.ExecuteDatasetEx(uox.db,"SELECT * FROM ts_PropertyTypeType").Tables[0],"Name","ID");
		}

		private string BuildSelectOptions(DataTable dt,string textField,string valueField){
			XmlDocument doc = new XmlDocument();
			doc.LoadXml("<SELECT/>");
			foreach( DataRow row in dt.Rows ){
				XmlElement el = doc.CreateElement("OPTION");
				el.SetAttribute("value",row[valueField]+"");
				el.InnerText = row[textField]+"";
				doc.DocumentElement.AppendChild(el);
			}
			return doc.DocumentElement.InnerXml;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}